import pandas_alive
path ="/Users/parsanemati/Yandex.Disk.localized/github/data_science_eda/pandas_live/"
covid_df = pandas_alive.load_dataset()
covid_df.plot_animated(
filename=path + 'examples/perpendicular-example.gif', perpendicular_bar_func='mean' ,period_length=50 , dpi=45)
## Generating BarChartRace, plotting ['Belgium', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Iran', 'Ireland', 'Italy', 'Mexico', 'Netherlands', 'Portugal', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'USA', 'United Kingdom']
## BarChartRace(df= Belgium Brazil Canada ... Turkey USA United Kingdom
## date ...
## 2020-02-26 00:00:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 04:48:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 09:36:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 14:24:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 19:12:00 NaN NaN NaN ... NaN NaN NaN
## ... ... ... ... ... ... ... ...
## 2020-04-21 04:48:00 6050.8 2774.0 1941.4 ... 2282.4 44883.2 17532.6
## 2020-04-21 09:36:00 6103.6 2807.0 1974.8 ... 2305.8 45319.4 17687.2
## 2020-04-21 14:24:00 6156.4 2840.0 2008.2 ... 2329.2 45755.6 17841.8
## 2020-04-21 19:12:00 6209.2 2873.0 2041.6 ... 2352.6 46191.8 17996.4
## 2020-04-22 00:00:00 6262.0 2906.0 2075.0 ... 2376.0 46628.0 18151.0
##
## [281 rows x 20 columns], interpolate_period=True, steps_per_period=5, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title=None, fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label=True, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=False, kwargs={}, orientation='h', sort='desc', label_bars=True, bar_label_size=7, n_visible=20, fixed_order=False, perpendicular_bar_func='mean')
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:221: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:222: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:68: UserWarning: Plotting too many bars may result in undesirable output, use `n_visible=15` to limit number of bars
## warnings.warn(
from IPython.display import Image
Image(url=path + 'examples/perpendicular-example.gif')
covid_df.plot_animated(
filename=path + 'examples/example-barv-chart.gif', orientation='v' , period_length=50 , dpi=45)
## Generating BarChartRace, plotting ['Belgium', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Iran', 'Ireland', 'Italy', 'Mexico', 'Netherlands', 'Portugal', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'USA', 'United Kingdom']
## BarChartRace(df= Belgium Brazil Canada ... Turkey USA United Kingdom
## date ...
## 2020-02-26 00:00:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 04:48:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 09:36:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 14:24:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 19:12:00 NaN NaN NaN ... NaN NaN NaN
## ... ... ... ... ... ... ... ...
## 2020-04-21 04:48:00 6050.8 2774.0 1941.4 ... 2282.4 44883.2 17532.6
## 2020-04-21 09:36:00 6103.6 2807.0 1974.8 ... 2305.8 45319.4 17687.2
## 2020-04-21 14:24:00 6156.4 2840.0 2008.2 ... 2329.2 45755.6 17841.8
## 2020-04-21 19:12:00 6209.2 2873.0 2041.6 ... 2352.6 46191.8 17996.4
## 2020-04-22 00:00:00 6262.0 2906.0 2075.0 ... 2376.0 46628.0 18151.0
##
## [281 rows x 20 columns], interpolate_period=True, steps_per_period=5, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title=None, fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label=True, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=False, kwargs={}, orientation='v', sort='desc', label_bars=True, bar_label_size=7, n_visible=20, fixed_order=False, perpendicular_bar_func=None)
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/matplotlib/animation.py:887: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.
## warnings.warn(
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:227: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels(self.df.columns, ha="right")
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:228: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels([max_val] * len(ax.get_yticks()))
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:187: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels(ax.get_xticklabels(), ha="right", rotation=30)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:68: UserWarning: Plotting too many bars may result in undesirable output, use `n_visible=15` to limit number of bars
## warnings.warn(
from IPython.display import Image
Image(url=path + 'examples/example-barv-chart.gif')
With as many lines as data columns in the DataFrame.
covid_df.diff().fillna(0).plot_animated(filename=path + 'examples/example-line-chart.gif',
kind='line', period_label={'x': 0.25, 'y': 0.9} ,
period_length=50 , dpi=45)
## Generating LineChart, plotting ['Belgium', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Iran', 'Ireland', 'Italy', 'Mexico', 'Netherlands', 'Portugal', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'USA', 'United Kingdom']
## LineChart(df= Belgium Brazil Canada ... Turkey USA United Kingdom
## date ...
## 2020-02-26 00:00:00 0.0 0.0 0.0 ... 0.0 0.0 0.0
## 2020-02-26 04:48:00 0.0 0.0 0.0 ... 0.0 0.0 0.0
## 2020-02-26 09:36:00 0.0 0.0 0.0 ... 0.0 0.0 0.0
## 2020-02-26 14:24:00 0.0 0.0 0.0 ... 0.0 0.0 0.0
## 2020-02-26 19:12:00 0.0 0.0 0.0 ... 0.0 0.0 0.0
## ... ... ... ... ... ... ... ...
## 2020-04-21 04:48:00 188.8 156.2 179.8 ... 118.6 2316.2 817.0
## 2020-04-21 09:36:00 207.6 158.4 176.6 ... 118.2 2282.4 806.0
## 2020-04-21 14:24:00 226.4 160.6 173.4 ... 117.8 2248.6 795.0
## 2020-04-21 19:12:00 245.2 162.8 170.2 ... 117.4 2214.8 784.0
## 2020-04-22 00:00:00 264.0 165.0 167.0 ... 117.0 2181.0 773.0
##
## [281 rows x 20 columns], interpolate_period=True, steps_per_period=5, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title=None, fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label={'x': 0.25, 'y': 0.9}, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=False, kwargs={}, line_width=2, label_events=None, fill_under_line_color=None, add_legend=True)
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:458: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:459: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
from IPython.display import Image
Image(url=path + 'examples/example-line-chart.gif')
Similar to line charts with time as the x-axis.
import pandas_alive
covid_df.sum(axis=1).fillna(0).plot_animated(filename=path + 'examples/example-bar-chart.gif', kind='bar',
period_label={'x': 0.1, 'y': 0.9},
enable_progress_bar=True, steps_per_period=2, interpolate_period=True, period_length=50 , dpi=45
)
## Generating BarChart, plotting ['0']
## BarChart(df= 0
## date
## 2020-02-26 00:00:00 2750.0
## 2020-02-26 12:00:00 2770.5
## 2020-02-27 00:00:00 2791.0
## 2020-02-27 12:00:00 2819.0
## 2020-02-28 00:00:00 2847.0
## ... ...
## 2020-04-20 00:00:00 160955.0
## 2020-04-20 12:00:00 164024.0
## 2020-04-21 00:00:00 167093.0
## 2020-04-21 12:00:00 170106.5
## 2020-04-22 00:00:00 173120.0
##
## [113 rows x 1 columns], interpolate_period=True, steps_per_period=2, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title=None, fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label={'x': 0.1, 'y': 0.9}, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=True, kwargs={})
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:458: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:459: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
##
0%| | 0/113 [00:00<?, ?it/s]
6%|6 | 7/113 [00:00<00:01, 64.89it/s]
12%|#2 | 14/113 [00:00<00:01, 64.38it/s]/Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/matplotlib/animation.py:887: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.
## warnings.warn(
##
19%|#8 | 21/113 [00:00<00:01, 53.17it/s]
24%|##3 | 27/113 [00:00<00:01, 52.85it/s]
29%|##9 | 33/113 [00:00<00:01, 50.53it/s]
35%|###4 | 39/113 [00:00<00:01, 48.17it/s]
39%|###8 | 44/113 [00:00<00:01, 46.02it/s]
43%|####3 | 49/113 [00:01<00:01, 44.20it/s]
48%|####7 | 54/113 [00:01<00:01, 42.67it/s]
52%|#####2 | 59/113 [00:01<00:01, 40.33it/s]
57%|#####6 | 64/113 [00:01<00:01, 38.16it/s]
60%|###### | 68/113 [00:01<00:01, 34.62it/s]
64%|######3 | 72/113 [00:01<00:01, 33.12it/s]
67%|######7 | 76/113 [00:01<00:01, 31.50it/s]
71%|####### | 80/113 [00:01<00:01, 30.29it/s]
74%|#######4 | 84/113 [00:02<00:00, 29.25it/s]
77%|#######6 | 87/113 [00:02<00:00, 28.70it/s]
80%|#######9 | 90/113 [00:02<00:00, 28.09it/s]
82%|########2 | 93/113 [00:02<00:00, 26.24it/s]
85%|########4 | 96/113 [00:02<00:00, 26.09it/s]
88%|########7 | 99/113 [00:02<00:00, 25.78it/s]
90%|######### | 102/113 [00:02<00:00, 25.61it/s]
93%|#########2| 105/113 [00:02<00:00, 25.18it/s]
96%|#########5| 108/113 [00:03<00:00, 24.14it/s]
98%|#########8| 111/113 [00:03<00:00, 22.48it/s]
100%|##########| 113/113 [00:03<00:00, 31.50it/s]
from IPython.display import Image
Image(url=path + 'examples/example-bar-chart.gif')
import pandas as pd
import pandas_alive
max_temp_df = pd.read_csv(
path + "data/Newcastle_Australia_Max_Temps.csv",
parse_dates={"Timestamp": ["Year", "Month", "Day"]},
)
min_temp_df = pd.read_csv(
path + "data/Newcastle_Australia_Min_Temps.csv",
parse_dates={"Timestamp": ["Year", "Month", "Day"]},
)
merged_temp_df = pd.merge_asof(max_temp_df, min_temp_df, on="Timestamp")
merged_temp_df.index = pd.to_datetime(
merged_temp_df["Timestamp"].dt.strftime('%Y/%m/%d'))
keep_columns = [
"Minimum temperature (Degree C)", "Maximum temperature (Degree C)"]
merged_temp_df[keep_columns].resample("Y").mean().plot_animated(
filename=path + 'examples/example-scatter-chart.gif', kind="scatter", title='Max & Min Temperature Newcastle, Australia' , period_length=50 , dpi=45)
## Generating ScatterChart, plotting ['Minimum temperature (Degree C)', 'Maximum temperature (Degree C)']
## ScatterChart(df= Minimum temperature (Degree C) Maximum temperature (Degree C)
## Timestamp
## 1957-12-31 00:00:00.000000000 14.502727 21.561212
## 1958-03-14 01:13:08.571428571 14.628573 21.525994
## 1958-05-26 02:26:17.142857142 14.754419 21.490777
## 1958-08-07 03:39:25.714285712 14.880264 21.455559
## 1958-10-19 04:52:34.285714284 15.006110 21.420342
## ... ... ...
## 2020-03-13 19:07:25.714285568 16.157607 23.516883
## 2020-05-25 20:20:34.285714176 16.816040 23.885281
## 2020-08-06 21:33:42.857142784 17.474473 24.253680
## 2020-10-18 22:46:51.428571392 18.132906 24.622078
## 2020-12-31 00:00:00.000000000 18.791339 24.990476
##
## [316 rows x 2 columns], interpolate_period=True, steps_per_period=5, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title='Max & Min Temperature Newcastle, Australia', fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label=True, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=False, kwargs={}, size=2, add_legend=True)
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:458: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:459: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/charts.py:420: UserWarning: Discarding nonzero nanoseconds in conversion.
## super().set_x_y_limits(self.df, i, self.ax)
from IPython.display import Image
Image(url=path + 'examples/example-scatter-chart.gif')
covid_df.plot_animated(filename=path+ 'examples/example-pie-chart.gif',
kind="pie", rotatelabels=True, period_label={'x': 0, 'y': 0} ,
period_length=50 , dpi=45)
## Generating PieChart, plotting ['Belgium', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Iran', 'Ireland', 'Italy', 'Mexico', 'Netherlands', 'Portugal', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'USA', 'United Kingdom']
## PieChart(df= Belgium Brazil Canada ... Turkey USA United Kingdom
## date ...
## 2020-02-26 00:00:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 04:48:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 09:36:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 14:24:00 NaN NaN NaN ... NaN NaN NaN
## 2020-02-26 19:12:00 NaN NaN NaN ... NaN NaN NaN
## ... ... ... ... ... ... ... ...
## 2020-04-21 04:48:00 6050.8 2774.0 1941.4 ... 2282.4 44883.2 17532.6
## 2020-04-21 09:36:00 6103.6 2807.0 1974.8 ... 2305.8 45319.4 17687.2
## 2020-04-21 14:24:00 6156.4 2840.0 2008.2 ... 2329.2 45755.6 17841.8
## 2020-04-21 19:12:00 6209.2 2873.0 2041.6 ... 2352.6 46191.8 17996.4
## 2020-04-22 00:00:00 6262.0 2906.0 2075.0 ... 2376.0 46628.0 18151.0
##
## [281 rows x 20 columns], interpolate_period=True, steps_per_period=5, period_length=50, period_fmt='%d/%m/%Y', figsize=array([6.5, 3.5]), title=None, fig=<Figure size 292.5x157.5 with 1 Axes>, cmap='dark24', tick_label_size=7, period_label={'x': 0, 'y': 0}, period_summary_func=None, fixed_max=False, dpi=45, writer=None, enable_progress_bar=False, kwargs={'rotatelabels': True})
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:458: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:459: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/matplotlib/animation.py:887: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.
## warnings.warn(
from IPython.display import Image
Image(url=path + 'examples/example-pie-chart.gif')
Bubble charts are generated from a multi-indexed dataframes. Where the index is the time period (optional) and the axes are defined with x_data_label & y_data_label which should be passed a string in the level 0 column labels. When you set color_data_label= to a df column name, pandas_alive will automatically add a colorbar.
import pandas_alive
multi_index_df = pd.read_csv(path + "data/multi.csv", header=[0, 1], index_col=0)
multi_index_df.index = pd.to_datetime(multi_index_df.index, dayfirst=True)
map_chart = multi_index_df.plot_animated(
kind="bubble",
filename=path + "examples/example-bubble-chart.gif",
x_data_label="Longitude",
y_data_label="Latitude",
size_data_label="Cases",
color_data_label="Cases",
vmax=5, steps_per_period=3, interpolate_period=True, period_length=500,
dpi=45
)
## Generating BubbleChart, plotting ['Cases', 'Latitude', 'Longitude']
##
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:458: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_yticklabels(self.df.columns)
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/pandas_alive/_base_chart.py:459: UserWarning: FixedFormatter should only be used together with FixedLocator
## ax.set_xticklabels([max_val] * len(ax.get_xticks()))
## /Users/parsanemati/Library/r-miniconda-arm64/envs/pandas_live/lib/python3.8/site-packages/matplotlib/animation.py:887: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.
## warnings.warn(
from IPython.display import Image
Image(url=path + 'examples/example-bubble-chart.gif')